/*
 * B 站直播弹幕机
 * 
 * @author Zdream
 * @date 2021-01-24
 * @since 0.4.1
 */

function create (context) {
	return {
		template : context.template,
		data : function () {
			return {
        roomId : null,
        // 状态数据
				status : null,
			}
		},
		props : {
			sid : String,
		},
		methods : {
			onScreenUpdated : function () {
        let status = this.status = context.getStatus(this.sid);
        if (!status || !status.data) {
					return;
				}
				if (status.data) {
					this.roomId = status.data.roomId <= 0 ? this.roomId : status.data.roomId;
				}
			},
			// 事件驱动
			editRoomIdSubmit : function () {
        if (this.roomId == null) {
          //
          return;
        }
				context.sendCommand(this.sid, 'room', {roomId : this.roomId});
			}
		},
		mounted : function () {
			this.onScreenUpdated(); // 更新 chunkWidth
			context.getBus().$on('screen-status-sync-all', this.onScreenUpdated);
			context.getBus().$on('screen-updated', this.onScreenUpdated);
			context.getBus().$on('screen-destroyed', this.onScreenUpdated);
		},
    destroyed : function () {
      context.getBus().$off('screen-status-sync-all', this.onScreenUpdated);
      context.getBus().$off('screen-updated', this.onScreenUpdated);
      context.getBus().$off('screen-destroyed', this.onScreenUpdated);
    }
	};
}

export default create;
